package com.aca.market.controller;

import com.aca.market.entity.Catalog;
import com.aca.market.entity.Role;
import com.aca.market.entity.User;
import com.aca.market.service.ICatalogService;
import com.aca.market.service.IRoleService;
import com.aca.market.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @Description: 校验用 kp版本
 * @author: kp
 * @date: 2020/12
 * @param:
 * @return:
 */
@Controller
public class CheckController {
    @Autowired
    IUserService userService;
    @Autowired
    ICatalogService catalogService;
    @Autowired
    IRoleService roleService;

    @ResponseBody
    @RequestMapping(value="/verifyAddIntent_UId",method= RequestMethod.GET)
    public boolean verifyAddIntent_UId(@RequestParam("userId") int userId){
        if(userService.getById(userId)!=null)
            return true;
        return false;
    }

    @ResponseBody
    @RequestMapping(value="/verifyAddUser",method= RequestMethod.GET)
    public boolean verifyAddUser(@RequestParam("username") String username){
        if(userService.getOne(new QueryWrapper<User>().eq("username",username))==null)
            return true;
        return false;
    }

    @ResponseBody
    @RequestMapping(value = "/verifyTypeName",method = RequestMethod.GET)
    public boolean verifyTypeName(@RequestParam("typeName") String typeName){
        if(catalogService.getOne(new QueryWrapper<Catalog>().eq("type_name",typeName))==null)
            return true;
        return false;
    }

    @ResponseBody
    @RequestMapping(value = "/verifyRoleName",method = RequestMethod.GET)
    public boolean verifyRoleName(@RequestParam("name") String roleName){
        if(roleService.getOne(new QueryWrapper<Role>().eq("name",roleName))==null)
            return true;
        return false;
    }
}
